package com.gosophia.conferenceManagement.common.test.integration;

import junit.framework.Assert;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
import org.springframework.transaction.annotation.Transactional;

import com.gosophia.commons.exception.BusinessException;
import com.gosophia.conferenceManagement.common.entity.ConferenceJobData;
import com.gosophia.conferenceManagement.common.service.ConferenceHandleService;
import com.gosophia.conferenceManagement.dao.ConferenceJobDataDAO;
import com.gosophia.taskManagement.dao.JobDao;

@ContextConfiguration(locations = { "classpath*:moduleContext.xml",
"classpath:applicationContext-it.xml" })
@Transactional(rollbackFor = { BusinessException.class })
public class ITConferenceHandleServiceImpl extends AbstractTransactionalJUnit4SpringContextTests {

	@Autowired
	private JobDao jobDao;
	
	@Autowired
	private ConferenceJobDataDAO cDAO;
	
	@Autowired
	@Qualifier("conferenceHandleService")
	private ConferenceHandleService conferenceHandleService;
	
	@Test(expected = IllegalArgumentException.class)
	public void testAddConferenceJobDataWithNull() throws BusinessException {
		conferenceHandleService.addConferenceJobData(null);
	}
	
	@Test(expected = IllegalArgumentException.class)
	public void testAddConferenceJobDataWithIdNotNull() throws BusinessException{
		ConferenceJobData c = new ConferenceJobData();
		c.setJobDataId(0L);
		conferenceHandleService.addConferenceJobData(c);
	}
	
	@Test
	public void testAddConferenceJobData() throws BusinessException {
		ConferenceJobData c = new ConferenceJobData();
		c.setJob(jobDao.get(1L));
		c.setOpinion("opinion");
		conferenceHandleService.addConferenceJobData(c);
		cDAO.flush();
		int num = cDAO.getAll().size();
		Assert.assertEquals(3, num);
		
	}
	
	@Test
	public void testUpdateConferenceJobData() throws BusinessException {
		ConferenceJobData c = cDAO.get(1L);
		c.setOpinion("oo");
		conferenceHandleService.updateConferenceJobData(c);
		cDAO.flush();
		cDAO.clearSession();
		ConferenceJobData newC = cDAO.get(1L);
		Assert.assertEquals("oo", newC.getOpinion());
	}

//	@Test
//	public void testFindConferenceJobDataByJobDataId() {
//		fail("Not yet implemented");
//	}
//
//	@Test
//	public void testHandleConferenceTurning() {
//		fail("Not yet implemented");
//	}
//
//	@Test
//	public void testStartingConferenceProcessing() {
//		fail("Not yet implemented");
//	}
}
